package org.lanqiao.controller.information;


import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.lanqiao.config.entity.ResponseData;
import org.lanqiao.information.IInfoService;
import org.lanqiao.information.Information;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("Info")
@Api(tags = "资源管理模块Infomation")
public class infoController {
    @Reference
    private IInfoService iInfoService;

    @GetMapping("/OrderByCreatetime")
    @ApiOperation(value = "时间排序",notes = "获取所信息根据creat_time排序")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "第一级分类",name = "sort1id",required = true, dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第二级分类",name = "sort2id",required = false,dataType = "Integer",paramType = "query")
    })
    public ResponseData<Information> OrderByCreatetime(@RequestParam Integer sort1id, @RequestParam Integer sort2id){
        List<Information> infoList =  iInfoService.InforListByCreateTime(sort1id, sort2id);
        if(infoList!= null){
            return  ResponseData.success().putDataVule("infoList",infoList);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/OrderByReads")
    @ApiOperation(value = "访问排序",notes = "获取所信息根据访问量排序")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "第一级分类",name = "sort1id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第二级分类",name = "sort2id",required = false,dataType = "Integer",paramType = "query")
    })
    public ResponseData<Information> OrderByReads(@RequestParam Integer sort1id, @RequestParam Integer sort2id){
        List<Information> infoList =  iInfoService.InforListByReads(sort1id, sort2id);
        if(infoList!= null){
            return  ResponseData.success().putDataVule("infoList",infoList);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/OrderByLike")
    @ApiOperation(value = "点赞排序",notes = "获取所信息根据点赞量排序")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "第一级分类",name = "sort1id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第二级分类",name = "sort2id",required = false,dataType = "Integer",paramType = "query")
    })
    public ResponseData<Information> OrderByLike(@RequestParam Integer sort1id, @RequestParam Integer sort2id){
        List<Information> infoList =  iInfoService.InforListByLike(sort1id, sort2id);
        if(infoList!= null){
            return  ResponseData.success().putDataVule("infoList",infoList);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/OrderByCollect")
    @ApiOperation(value = "收藏量排序",notes = "获取所信息根据收藏量排序")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "第一级分类",name = "sort1id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第二级分类",name = "sort2id",required = false,dataType = "Integer",paramType = "query")
    })
    public ResponseData<Information> OrderByCollect(@RequestParam Integer sort1id, @RequestParam Integer sort2id){
        List<Information> infoList =  iInfoService.InforListByCollect(sort1id, sort2id);
        if(infoList!= null){
            return  ResponseData.success().putDataVule("infoList",infoList);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/InforListByChecking")
    @ApiOperation(value = "待审核的资源",notes = "获取所待审核的资源")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "第一级分类",name = "sort1id",required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第二级分类",name = "sort2id",required = false,dataType = "Integer",paramType = "query")
    })
    public ResponseData<Information> InforListByChecking(@RequestParam Integer sort1id, @RequestParam Integer sort2id){
        List<Information> infoList =  iInfoService.InfoListByChecking(sort1id, sort2id);
        if(infoList!= null){
            return  ResponseData.success().putDataVule("infoList",infoList);
        }else{
            return ResponseData.serverInternalError();
        }
    }

    @PostMapping("/SelectByCondition")
    @ApiOperation(value = "条件查询",notes = "根据条件查询 queryMap中可以包含的参数有sort1id sort2id  infotitle infocontent createtime updatetime infourl infostatus orderByDesc orderByAsc")
    @ApiImplicitParam(value = "查询条件" ,name="queryMap" ,required = false,dataType = "Map",paramType = "body")
    public ResponseData<Information> SelectByCondition(@RequestBody Map<String,Object> queryMap){
        List<Information> infoList = iInfoService.QueryByCondition(queryMap);
        if(infoList!= null){
            return  ResponseData.success().putDataVule("infoList",infoList);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @PostMapping("/SelectPageByCondition")
    @ApiOperation(value = "分页条件查询",notes ="参数有pagenum pagesize根据条件查询 queryMap中可以包含的参数有sort1id sort2id  infotitle infocontent createtime updatetime infourl infostatus orderByDesc orderByAsc")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当前页数" ,name="pagenum" ,required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "每页显示条数" ,name="pagesize" ,required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "查询条件" ,name="queryMap" ,required = false,dataType = "Map",paramType = "body")
    })
    public ResponseData<Information> SelectPageByCondition(@RequestParam Integer pagenum,@RequestParam Integer pagesize,@RequestBody Map<String, Object> queryMap){
        IPage<Information> infoPage =  iInfoService.QueryConditionPage(queryMap, pagenum, pagesize);
        return ResponseData.success().putDataVule("totla",infoPage.getTotal())
                .putDataVule("pages",infoPage.getPages())
                .putDataVule("infoList",infoPage.getRecords());
    }

    @GetMapping("/SelectByPage")
    @ApiOperation(value = "分页查询",notes = "输入当前页数 每页显示条数根据sort1id sort2id查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "第一级分类",name = "sort1id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第二级分类",name = "sort2id",required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "当前页数" ,name="pagenum" ,required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "每页显示条数" ,name="pagesize" ,required = false,dataType = "Integer",paramType = "query"),
    })
    public  ResponseData<Information> SelectByPage(Integer sort1id, Integer sort2id, Integer pagenum, Integer pagesize){
        IPage<Information> infopage =iInfoService.InfoListPage(sort1id, sort2id, pagenum, pagesize);
        return ResponseData.success().putDataVule("totla",infopage.getTotal())
                .putDataVule("pages",infopage.getPages())
                .putDataVule("InifoList",infopage.getRecords());
    }

    @GetMapping("/DeleteInformation")
    @ApiOperation(value = "删除一个资源",notes = "删除资源")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> DeleteInformation(Integer id){
        Integer result = iInfoService.deleteInfomation(id);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @PostMapping("/AddInformation")
    @ApiOperation(value = "新增一个资源",notes = "新增资源")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "资源发布者id",name = "userid",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第一级分类",name = "sort1id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第二级分类",name = "sort2id",required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "资源标题" ,name="infotitle" ,required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "资源的具体内容" ,name="infocontent" ,required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "资源附带的链接" ,name="infourl" ,required = false,dataType = "String",paramType = "query")
    })
    public ResponseData<Information> AddInformation( Integer userid,Integer sort1id, Integer sort2id, String infotitle, String infocontent, String infourl){
        Integer result = iInfoService.addInformation(userid, sort1id, sort2id, infotitle, infocontent,infourl);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/UpdateInformation")
    @ApiOperation(value = "更新一个资源",notes = "更新资源")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第一级分类",name = "sort1id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "第二级分类",name = "sort2id",required = false,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "资源标题" ,name="infotitle" ,required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(value = "资源的具体内容" ,name="infocontent" ,required = false,dataType = "String",paramType = "query"),
            @ApiImplicitParam(value = "资源附带的链接" ,name="infourl" ,required = false,dataType = "String",paramType = "query")
    })
    public ResponseData<Information> UpdateInformation(Integer id, Integer sort1id, Integer sort2id, String infotitle, String infocontent, String infourl){
        Integer result = iInfoService.updateInformation(id, sort1id, sort2id, infotitle, infocontent,infourl);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/SelectOne")
    @ApiOperation(value = "获取一个information",notes = "根据id获取一个information")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> SelectOne(Integer id){
        Information information = iInfoService.selectOnes(id);
        if(information!= null){
            return  ResponseData.success().putDataVule("information",information);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/GetLikeCount")
    @ApiOperation(value = "获取点赞数",notes = "根据id获取点赞总数")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> GetLikeCount(Integer id){
        Integer likeConuntsum = iInfoService.getLikeConunt(id);
        if(likeConuntsum!= null){
            return  ResponseData.success().putDataVule("likeConuntsum",likeConuntsum);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/GetResponse")
    @ApiOperation(value = "获取回复数",notes = "根据id获取回复数总数")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> GetResponse(Integer id){
        Integer likeconuntsum = iInfoService.getResponse(id);
        if(likeconuntsum!= null){
            return  ResponseData.success().putDataVule("likeconuntsum",likeconuntsum);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/GetReads")
    @ApiOperation(value = "获取访问量",notes = "根据id获取访问量总数")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> GetReads(Integer id){
        Integer readsnum = iInfoService.getReads(id);
        if(readsnum!= null){
            return  ResponseData.success().putDataVule("readsnum",readsnum);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/LikeCountAddone")
    @ApiOperation(value = "点赞数加一",notes = "根据id使得点赞数加一")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> LikeCountAddone(Integer id){
        Integer result = iInfoService.addoneLikeCount(id);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/LikeCountDelone")
    @ApiOperation(value = "点赞数减一",notes = "根据id使得点赞数减一")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> LikeCountDelone(Integer id){
        Integer result = iInfoService.deloneLikeCount(id);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/ReadsAddone")
    @ApiOperation(value = "访问量数加一",notes = "根据id使访问量加一")
    public ResponseData<Information> ReadsAddone(Integer id){
        Integer result = iInfoService.addoneReads(id);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/ResponseAddone")
    @ApiOperation(value = "回复数加一",notes = "根据id使回复数加一")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> ResponseAddone(Integer id){
        Integer result = iInfoService.addoneResponse(id);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/ResponseDelone")
    @ApiOperation(value = "回复数减一",notes = "根据id使回复数减一")
    @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Information> ResponseDelone(Integer id){
        Integer result = iInfoService.deloneResponse(id);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("ChangeStatus")
    @ApiOperation(value = "改变状态",notes = "根据id改变当前自愿的状态")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "资源id",name = "id",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "需要改变的转态0-4" ,name="status" ,required = true,dataType = "Integer",paramType = "query")
    })
    public ResponseData<Information> ChangeStatus(Integer id, Integer status){
        Integer result = iInfoService.ChangeStatus(id, status);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }

}

